package com.cw.jeeyt.service.intf.security;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;

import com.cw.jeeyt.service.bo.security.SecurityResourceBo;
import com.cw.lang.mybatis.dto.PageInfo;

/**
 * 资源信息业务接口
  * @author chenw
 * @version 1.0.0
 */
public interface SecurityResourceService extends FilterInvocationSecurityMetadataSource {
    /**
     * 重置保存在redis的资源信息
     *
     * @throws Exception
     */
    void refreshSecurityResource() throws Exception;

    /**
     * 删除资源信息
     *
     * @param resourceBo
     */
    void delete(SecurityResourceBo resourceBo) throws Exception;

    /**
     * 更新资源信息
     *
     * @param resourceBo
     */
    void update(SecurityResourceBo resourceBo) throws Exception;

    /**
     * 根据主键查询资源信息
     *
     * @param id
     * @return
     */
    SecurityResourceBo getResourceById(Long id) throws Exception;

    /**
     * 新增资源信息
     *
     * @param resourceBo
     * @return
     */
    boolean insert(SecurityResourceBo resourceBo) throws Exception;

    /**
     * 分页查询资源信息
     *
     * @param resourceBo
     * @param startNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    PageInfo<SecurityResourceBo> queryByPage(SecurityResourceBo resourceBo, Integer startNum, Integer pageSize)
    throws Exception;

    /**
     * 同步菜单信息到资源信息
     *
     * @param resourceJson
     * @throws Exception
     */
    void asyncResource(String resourceJson) throws Exception;

    /**
     * 根据用户名称查询用户资源
     *
     * @param userName
     * @return
     * @throws Exception
     */
    List<SecurityResourceBo> getResourceByUserName(String userName) throws Exception;

    /**
     * 根据角色id查询资源信息
     *
     * @param roleId
     * @return
     * @throws Exception
     */
    List<SecurityResourceBo> getResourceByRoleId(Long roleId) throws Exception;

    /**
     * 查询根节点资源信息
     *
     * @return
     * @throws Exception
     */
    SecurityResourceBo queryRootSecurityResource() throws Exception;

    /**
     * 加载当前资源id下的资源信息
     *
     * @param type 赋权的类型 角色 用户
     * @param assignId 资源id
     * @param parentIsOpen 父节点是否打开
     * @param childIsOpen 子节点是否打开
     * @return
     * @throws Exception
     */
    String queryResourceJson(Long resId, String type, Long assignId, boolean parentIsOpen, boolean childIsOpen)
    throws Exception;

    /**
     * 更新父节点id
     *
     * @param id
     * @param parentId
     * @throws Exception
     */
    void updateResourceParentId(Long id, Long parentId) throws Exception;

    /**
     * 更新资源名称
     *
     * @param id
     * @param resName
     * @throws Exception
     */
    void updateResourceName(Long id, String resName) throws Exception;

    /**
     * 根据父节点加载资源信息
     *
     * @param parentId
     * @return
     */
    List<SecurityResourceBo> querySecurityResourceListByParentId(Long parentId) throws Exception;

    /**
     * @param parentId
     * @param parentIsOpen
     * @param childIsOpen
     * @return
     * @throws Exception
     */
    String queryResourceJson(Long parentId, boolean parentIsOpen, boolean childIsOpen) throws Exception;

    /**
     * 查询选择资源列表
     *
     * @param securityResourceBo
     * @param start
     * @param length
     * @return
     * @throws Exception
     */
    PageInfo<SecurityResourceBo> querySelectSecurityResource(SecurityResourceBo securityResourceBo, Integer start,
        Integer length) throws Exception;

    /**
     * 保存资源信息
     *
     * @param securityResourceBo
     * @return
     * @throws Exception
     */
    Integer saveSecurityResource(SecurityResourceBo securityResourceBo) throws Exception;

    /**
     * 更新资源信息
     *
     * @param securityResourceBo
     * @throws Exception
     */
    void updateSecurityResource(SecurityResourceBo securityResourceBo) throws Exception;

    /**
     * 根据登录用户查询资源菜单
     *
     * @param userId
     * @param request
     * @return
     * @throws Exception
     */
    String queryResourceByLoginUser(Long userId, HttpServletRequest request) throws Exception;

    /**
     * 刷新资源缓存
     *
     * @throws Exception
     */
    void refreshResource() throws Exception;

    /**
     * 根据父id及资源名称查询资源信息
     *
     * @param resName
     * @param parentId
     * @return
     */
    SecurityResourceBo getResByResNameAndParentId(String resName, Long parentId);

    /**
     * 批量新增资源信息
     *
     * @param securityResourceList
     * @throws Exception
     */
    void insertBat(List<SecurityResourceBo> securityResourceList) throws Exception;

    /**
     * 判断访问URL是否需要访问权限
     *
     * @param url
     * @return
     */
    boolean checkResourceNeedAuth(String url);
}
